import pandas as pd
import os

if __name__ == '__main__':
    Path = os.path.abspath(os.path.dirname(__file__))
    excel_data = pd.read_excel(Path + "/email.xlsx", engine="openpyxl")
    emails = excel_data.iloc[1:].values
    email_list = []
    err_list = []
    for email in emails:
        if type(email[4]) == str:
            if '@' in email[4]:
                email_list.append(email[4])
            else:
                err_list.append(email[4])

    tail_email = []
    for i in email_list:
        c = i.split("@")[1]
        if c != "":
            tail_email.append(c)
    set_tail_email = set(tail_email)
    tail_email_dict = {}
    for item in set_tail_email:
        # print("the %s has found %d" % (item, tail_email.count(item)))
        tail_email_dict[item] = tail_email.count(item)
    tail_email_dict_sorted = sorted(zip(tail_email_dict.values(), tail_email_dict.keys()), reverse=True)
    for tail_dict in tail_email_dict_sorted:
        print("the %s has found %d" % (tail_dict[1], tail_dict[0]))
